home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Newsletters / GEnieUnixNews / unxnl-06.91 < prev    next >
Text File  |  1992-12-27  |  20KB  |  485 lines

  1.  
  2.           _ __  _   _ __ _ __
  3.          // /  //| // || \\|     N E W S
  4.         //_/  // |//  ||  |\\    Vol 2, Issue 3 - June 1991
  5.          R o u n d T a b l e
  6.  
  7.    Items of interest to participants of the GEnie Unix RoundTable
  8.  
  9.       The RoundTable SysOps are:
  10.       Dave Weinstein......OLORIN     Brian Riley.........DELPHI
  11.       Gary Smith..........GARS       Chris North-Keys....HARP
  12.       Rick Mobley.........LRARK    All Unix SysOps.....UNIXSYSOPS$
  13.    We strongly encourage you to contact any or all of us if you have -ANY-
  14.  comments or suggestions. This is -YOUR- RoundTable. We are here to make
  15.  your participation as pleasant and beneficial as possible.
  16.  
  17.  ED: editor notes - AWK rules (this issue)
  18.  --
  19.    In recent issues I have included a few notes on AWK usage and some example
  20.  scripts. I was both surprised and pleased that many were quite interested in
  21.  AWK and wanted more of the same. With that in mind I endeavored to collect
  22.  several worthwhile examples from news articles. The end result is this will
  23.  be the second newsletter that supports a central theme - the theme this issue
  24.  is obviously AWK scripts.
  25.    Would more of the same be in order for a future issue, or would readers be
  26.  interested in sed or perl ? Please leave comments or votes via GEnie e-mail 
  27.  to GARS.
  28.  
  29.  GUI Article - continued
  30.  -----------
  31.      by Dave Weinstein (OLORIN)
  32.           
  33.     [ Ed. note: Dave began this look at GUI's in Unix RoundTable newsletter
  34.                 volume 2, issue 2 available in GEnie Unix RoundTable library
  35.                 1 as UNXNL-04.91 ]
  36.  
  37.        The continuing GUI Saga
  38.  
  39.    It's done. It's in Beta. It's not working *quite* the way you expected.
  40.  
  41.    Macro recorder's are your friend. Requiring all bug reports to accompany
  42.  a recording of all of the various movements, clicks, and keystrokes required
  43.  to break your code can make your life easier (especially if your duties 
  44.  involve bug xifixes and support, continuing upgrades to the Beta version, 
  45.  and preliminary work on the next set of features to be added) [Note: any 
  46.  similarities between the described conditions and the author's current state 
  47.  are due to the fact that he has spent too much time fixing bugs and not 
  48.  nearly enough time doing anything else]. Many times, the user's don't think 
  49.  right (or at least, they don't think the way you do), and watching exactly 
  50.  what they do can be the difference between quickly finding and fixing a 
  51.  problem and spending 30 hours trying to figure out just what the users mean 
  52.  by "it doesn't do the window right".
  53.  
  54.    On the other hand, you may be trying out a new GUI based product. You
  55.  can make the developer's life easier (and get fixes faster), by being
  56.  very clear in describing what has broken, how, and when, and by duplicating
  57.  the problem on your end before calling in the bug.
  58.  
  59.    Flip through the trade journals; it's getting impossible to turn a
  60.  page without looking at information on everyone's graphics based product.
  61.  More and more mainframe applications are aquiring graphical interfaces.
  62.  Using them, writing them, and figuring out why they don't do what the vendor
  63.  says they do is an easier task if everyone can agree on what was done to
  64.  make them fail.
  65.  
  66.   --Dave
  67.  
  68.   FAST and NASTY, DOWN  and  DIRTY:  quick  fix scripts that do something
  69.  --------------------------------
  70.     no quick scripts this issue so we can devote more space to AWK usage.
  71.       Gary
  72.   
  73.  AWK USAGE - Several news articles collected to demonstrate awk's power
  74.  ---------   and some scripts to demonstrate usage.
  75.   
  76.  MAKING AWK OUTPUT INTO A VARIBLE :
  77.  ................................
  78.   
  79.  In article <1991Mar7.115420.21315@daimi.aau.dk>, 
  80.                       ezra@daimi.aau.dk (Thomas Ravnholt) writes:
  81.  |> Hello !
  82.  |> 
  83.  |>   I have a little question about awk (nawk).
  84.  |> 
  85.  |>   If I want to run a unix-command in an awk-script,
  86.  |> how do I get the output into a variable.
  87.  |> 
  88.  |>   I tried
  89.  |> 
  90.  |>      getline < system(unixcommand)
  91.  |> 
  92.  |>      system(unixcommand | getline)
  93.  |> 
  94.  |> 
  95.  |> but it is no good of course. system returns 0 or 1 and
  96.  |> not the output of the unixcommand.
  97.  |> 
  98.  
  99.  Crude, but effective, temporary files are your friend.  Here's a
  100.  simple example that does what you ask.
  101.  
  102.  #! /bin/sh
  103.  
  104.  awk '
  105.  BEGIN {
  106.  system("date > /tmp/foo")
  107.  getline X < "/tmp/foo"
  108.  print X
  109.  }'
  110.  
  111.  You can use the pid if you are worried about stepping on duplicate
  112.  temp file names and insert a "trap" command to delete your temp
  113.  file(s) in case your script terminates prematurely.
  114.  
  115.       -Mark
  116.  -- 
  117.                             ___  ___ 
  118.                            / __||__ \ 
  119.  Mark Kennedy             ( |__  __| )  AT&T: (612) 482-2787
  120.  Control Data Corporation  \___||___/   E-Mail: mek@udev.cdc.com
  121.              check-ins happen
  122.       
  123.  MAKING CALLS FROM AWK :
  124.  .....................
  125.    
  126.  From Usenet comp.unix.shell: a Summary on making calls from awk:
  127.     
  128.  From: gaspar@inf.ethz.ch (Scott "gaspo" Gasparian)
  129.  Subject: SUMMARY: using sh vars in awk calls.
  130.  Summary: using /bin/sh vars in awk calls
  131.     
  132.  greetings all!
  133.      
  134.  Ok, thanks to all who replied, and since I got a couple "me toos",
  135.  heres the deal:
  136.       
  137.  Problem:
  138.          in a /bin/sh script, need to pass a regular sh variable
  139.          to the awk call, but the proper syntax is not-readily
  140.          discernable.
  141.       
  142.  Example:
  143.            
  144.          given sh vars $fred, call awk using fred, like so:
  145.        
  146.          wilma=`cat $filea | awk '{if($1==fred){print("match")}}'`
  147.      
  148.  Solution:
  149.          (1), escape out the sh variable by using single quotes.
  150.        
  151.          rhartman@thestepchild.esd.sgi.com (Robert Hartman) says:
  152.  >
  153.  >        .... awk '{ ... '$fred' ...}' ...
  154.  >
  155.  >Since single-quotes suppress variable substitution, if you want the shell
  156.  >to expand the reference you have to leave it outside.  Note that
  157.  >the whole awk argument is still treated as one word by the shell, since
  158.  >there is no white space between the single quotes and the expanded shell
  159.  >variable.
  160.        
  161.          Kenneth Herron <kherron@ms.uky.edu> agrees with a slightly
  162.          different syntax of
  163.  >
  164.  >         wilma=`cat ${file1} | awk '{if($1== "'$fred'"){print("match")}}'
  165.  >       or
  166.  >         wilma=`cat ${file1} | awk "{if(\$1==\"$fred\"){print(\"match\")}}"
  167.       
  168.          (2), the other possible way is to declare awk a variable after
  169.          the end of the awk script (in the man pages, but I cant find it)
  170.          like so:
  171.          
  172.          dwn@swbatl.sbc.com (David Neill-OKCy Mktg 405-278-4007) suggests
  173.      
  174.  >               wilma=`cat $file1 | awk '
  175.  >               $1 == fredvar {printf("match on %s\n",fredvar)}
  176.  >               ' fredvar="$fred"`
  177.        
  178.           and andyb@coat.com (Andy Behrens) explains:
  179.       
  180.  >    fred="barney"
  181.  >    wilma=` cat ${file1} |
  182.  >          awk '{
  183.  >                   if ($1 == fred {print("match")}
  184.  >                }' fred=${fred} - `
  185.  >
  186.  >Awk allows command line assignments of the form 'name=value'.  These
  187.  >assignments follow the awk script and precede the filenames.  In most
  188.  >versions of awk, you must have at least one filename on the command
  189.  >line.  If you want awk to read from standard input (as in the above
  190.  >example), you can use a filename of '-'.
  191.        
  192.  I've only tried the single quote method, and it works fine.  Some of
  193.  this is supposed to be dependent on your version of awk.  dont ask,
  194.  i dont know.
  195.      
  196.  Thanks for all the info!
  197.      
  198.  --gaspo.
  199.        
  200.  BTW, to the dude who thought my sig was "long and obnoxious", you wouldnt
  201.  like my hair either!
  202.         
  203.  /----------------------------------------------------------------------------\
  204.  | Scott "gaspo" Gasparian  --  System Administrator |"Do you go every Sunday?|
  205.  | Dept. Informatik, Eidg. Techn. Hochschule, Zurich | sounds to me like YOU  |
  206.  | ETH-Zentrum,  CH-8092  Zurich.  T# 01-01-254-7205 | are the addicted one." |
  207.  | gaspar@inf.ethz.ch | "Good friends we've had, or good friends we've lost,  |
  208.  | ..!ethz-inf!gaspar | along the way.In this proud land,you can't forget your|
  209.  | gaspo@scri.fsu.edu | past,so dry your tears I say. No woman, No cry." -BMW |
  210.  \----------------------------------------------------------------------------/
  211.  
  212.  AWK SCRIPT TO DELETE EMPTY LINES :
  213.  ................................
  214.  
  215.  Kristopher Stephens and and Mike Moore respond to a news request
  216.  for help generating a script to delete empty lines in a text file.
  217.  
  218.   First, from Kristopher Stephens:
  219.  
  220.  How about this:
  221.  
  222.          :
  223.          # sh or ksh
  224.          #
  225.          # Reduce all multiple consecutive "empty" lines to singles.  Process
  226.          # stdin (switch it to filename processing or either as you wish).
  227.          #
  228.  
  229.          # Make the T in the sed line a <TAB> char.  I leave it a T for
  230.          # this posting just for clarity.
  231.  
  232.          # Use sed to strip all trailing blanks and tabs
  233.          sed 's/[ T]*$//' |
  234.  
  235.          # Use awk to delete empty lines that follow empty lines
  236.          awk '
  237.                  $0 != "" {
  238.                          print
  239.                          prevnull = 0
  240.                          next
  241.                  }
  242.  
  243.                  prevnull == 0 {
  244.                          print
  245.                          prevnull = 1
  246.                  }' -
  247.  
  248.  The flow in the awk script is to look for non-null lines first on the
  249.  assumption that more input lines will be non-null than null.  If a line
  250.  is non-null, print it and set the null-marker off.  No need to test the
  251.  marker variable before setting it, that would take longer than simply
  252.  making the assignment every time.
  253.  
  254.  If we get past that first block, we are processing a null line.  If the
  255.  null-marker is off, print this null line and set the null-marker on.  Any
  256.  line not matching one of these two blocks is a null line following a null
  257.  line, and is ignored.
  258.  
  259.  This is a pretty standard approach for me to take.  I use sed to do editing
  260.  of an input-stream for awk, where I do the conditional work based on line
  261.  contents.  Since sed is faster than awk, the sed process typically writes
  262.  the data out faster than awk will take it in, so doing the line-editing in
  263.  sed instead of within the awk script is no performance penalty at all for
  264.  the shell script as a whole.  It is, in fact, a performance gain because
  265.  the awk script would take more time if I expanded its definition of a null
  266.  line to include blanks and tabs.
  267.  
  268.  ...Kris
  269.  --
  270.  Kristopher Stephens, | (408-746-6047) | krs@uts.amdahl.com | KC6DFS
  271.  Amdahl Corporation   |                |                    |
  272.       [The opinions expressed above are mine, solely, and do not    ]
  273.       [necessarily reflect the opinions or policies of Amdahl Corp. ]
  274.  
  275.  
  276.  ...and from Mike Moore:
  277.  
  278.  The sed script below works, but messes up on lines at the beginning
  279.  and end of the file.  It may also have problems with large files.
  280.  The awk script works wonderfully!
  281.  
  282.  in=`cat $1 | tr '\012' '^L'`
  283.  
  284.  echo $in | sed -e 's/^L^L[^L]*/\
  285.  \
  286.  /g' -e 's/^L/\
  287.  /g'
  288.  
  289.  #========================
  290.  
  291.  awk ' BEGIN { blank=0
  292.                line=0
  293.              }
  294.              {
  295.  # remove here...
  296.                if ( blank == 0 )
  297.                {
  298.                  if ( $0 != "" )
  299.                  {
  300.                    blank++
  301.  
  302.                    if ( line != 0 )
  303.                      print ""
  304.  
  305.                    print $0
  306.                  }
  307.                  else
  308.                    line++
  309.                }
  310.                else
  311.                {
  312.  # to here, if you do not want to account for blank lines at beginning
  313.  
  314.                  if ( $0 == "" )
  315.                    line=1
  316.                  else
  317.                  {
  318.                    if ( line != 0 )
  319.                    {
  320.                      print ""
  321.                      line=0
  322.                    }
  323.  
  324.                    print $0
  325.                  }
  326.  
  327.  # (and this...)
  328.                }
  329.  
  330.              }
  331.  
  332.  # remove here...
  333.        END   { if ( line != 0 )
  334.                  print ""
  335.              }
  336.  # to here, if you do not want to account for blank lines at end
  337.  
  338.              ' $1
  339.  
  340.  
  341.  #========================
  342.  
  343.  --
  344.  ---            | usual and obvious disclaimers etc...      | Never take a
  345.  Mike Moore     | (anyone daft enough to sue me deserves    | Scorpio seriously.
  346.  mike@x.co.uk   |  to win a share in my negative cashflow!) | I know, I am one.
  347.    
  348.  DIAL UP COMMUNICATIONS TUTORIAL : - Understanding modem terminology
  349.  -------------------------------
  350.                               Modem Talk
  351.                            by Ricky Mobley
  352.  
  353.  Modems come in many shapes and sizes and from many manufacturers.
  354.  Some manufacturers produce several styles themselves with many
  355.  different features to encompass a wide variety of users. It is very
  356.  interesting, as well as a good exercise, to compare the specifications
  357.  of these modems and to purchase the model that will best serve you.
  358.  
  359.  Most people are very satisfied with purchasing an asyncronous modem,
  360.  which sends each byte independently. Using this method ensures
  361.  compatibility with a large group of existing modems, but is slower and
  362.  sometimes more restrictive when it comes to actual data throughput.
  363.  Each byte consists of a start bit plus eight data bits plus one stop
  364.  bit. Thus, we are sending additional bits of information that actually
  365.  contain no useful data.
  366.   
  367.  Some standards had to be set in order to determine just which modem
  368.  would talk to another modem at the other end of a dial-up line. In
  369.  steps the CCITT, A French acronym for the International Telegraph and
  370.  Telephone Consultative Committee. Their standards, or 'recommendations'
  371.  as they have it, are published every so often in a set of 'fascicles',
  372.  whose color varies with the year. The current set is the 'blue books'
  373.  published in 1988. Listed below are some of these standards and a
  374.  description as to how they apply to our current technology.
  375.  
  376.  V.21:     300bps. Also known as Bell 103.
  377.  V.22:     1200bps, with fall back to 600bps. Also known as Bell 212.
  378.  V.22 bis: 2400bps, with fall back to V.22.
  379.  V.23:     1200bps with 75bps back channel, with fall back to
  380.            600bps/75bps.
  381.  V.29:     9600bps half duplex or four wire (used by FAX) with fall back
  382.            to 7200bps and 4800bps.
  383.  V.32:     9600bps with fall back to 4800bps.
  384.  V.32 bis: 14400bps with fall back to 12000bps, 9600bps, 7200bps and
  385.            4800 bps.
  386.  
  387.   Other standards you may encounter:
  388.  
  389.  V.24:     Connection between DCE and DTE. Effectively the same as
  390.            RS232, though V.24 only specifies the meaning of the
  391.            signals, not the connector nor the voltages used.
  392.  V.25 bis: A cryptic command language for modems.
  393.  V.42:     Error correction with asynchronous to synchronous conversion.
  394.  V.42 bis: Data compression using a Lempel-Ziv related technique, which
  395.            detects frequently occurring character strings and replaces
  396.            them with tokens. This is similar to Unix compress. Typical
  397.            compression for text is 50% or better; with nearly 20% gain
  398.            from synchronous conversion this reduces transmission time
  399.            by almost 60%.
  400.  
  401.  As you have probably noticed, when you exceed 2400 baud you are
  402.  running half duplex or some form of compression. These techniques are
  403.  further explained as a set of modem-to-modem protocols that provide
  404.  both error correction and compression known as Microcom Network
  405.  Protocols or MNP for short. The commonly encountered ones are:
  406.  
  407.  MNP2. Error correction using asynchronous transmission.
  408.  MNP3. Error correction using synchronous transmission between the
  409.        modems (the DTE interface is still asynchronous). Since each
  410.        eight-bit byte takes eight rather than ten bits to transmit
  411.        there is scope for a 20% increase in throughput. Unfortunately
  412.        the MNP3 protocol overhead is rather high so this increase is
  413.        not realized.
  414.  MNP4. Introduces `data phase optimization', which improves on the rather
  415.        inefficient protocol design of MNP2 and MNP3. Synchronous MNP4
  416.        comes closer to achieving the 20% throughput increase mentioned
  417.        above.
  418.  MNP5. Simple data compression. Dynamically arranges for commonly
  419.        occurring characters to be transmitted with fewer bits than rare
  420.        characters. It takes account of changing character frequencies
  421.        as it runs. Also encodes long runs of the same character specially.
  422.        Typically compresses text by 35%; with 20% for MNP4 this reduces
  423.        data by almost 50%.
  424.  
  425.  Many modern modems incorporate MNP5 or V.42 bis to compress data
  426.  before it is sent over the phone line. For this to be effective, the
  427.  modem must be fed data at a higher speed than the phone line speed. 
  428.  Compression is most useful for interactive sessions in the modem. If
  429.  you are sending files, compressing them on the computer before sending
  430.  is usually more effective. In this case, make sure that the modem is
  431.  not also trying to compress because already-compressed data will
  432.  usually become larger if re-compressed.
  433.  
  434.  For compression to work, it is essential that the data is sent over
  435.  an error-free link. Otherwise the modems could get out of sync and
  436.  hopelessly garble the data. Since common error correction protocols
  437.  are synchronous, there is usually a throughput gain there as well.
  438.  
  439.  Manufacturer claims that MNP5 provides a 2:1 reduction in size, or
  440.  that V.42 bis provides 4:1, should be taken with a grain of salt. 
  441.  These claims are only true for suitable data.
  442.  
  443.  Like compression, error correction is most useful for interactive use.
  444.  When sending files, it is generally best to let the computers at each end
  445.  do the correction, using a protocol like Kermit or uucp. However, the
  446.  ability of MNP4 and V.42 to send data synchronously may make it
  447.  worthwhile to use them.
  448.  
  449.  A discussion about modulation technique would not be complete without
  450.  mentioning PEP (Packetized Ensemble Protocol) devised by Telebit and
  451.  used in their Trailblazer modems. It can achieve throughput of 9600bps
  452.  or better, and is reported to be more resilient than V.32. However, it
  453.  is half duplex with a long turnaround time. So for file transfer it
  454.  generally has to be used with protocol spoofing.
  455.  
  456.  I have just touched on this subject and as you can see, it takes a lot
  457.  to get good reliable data from one end to another. There are many
  458.  methods to do it and lots of good usable equipment on the market today
  459.  to acomplish your task. Hopefully, with this little bit of data you
  460.  will better understand modem talk and be more knowledgable when you
  461.  are searching for that major modem purchase.
  462.  
  463.  ---------------    
  464.     REMINDER - This newsletter is being sent to you 'by request'. If you do
  465.  not wish to keep receiving it, e-mail a stop notice to GARS. On the other
  466.  hand, we would very much appreciate it if you would pass the word that we
  467.  do distribute this item near the tenth (10th) of the month of issue to any-
  468.  one on GEnie who requests it, and will gladly add any name that is requested
  469.  via the same route... e-mail to GARS.
  470.    P L E A S E  also remember contributions are most welcome. Please e-mail
  471.  items and/or suggestions to GARS.
  472.  
  473.  (EOF)
  474.  
  475.  Trademark and Copyright notices:
  476.  Unix is a Trademark of  AT&T; GEnie, LiveWire, and RoundTable are Trademarks
  477.  of General Electric Information Services  Company;  Xenix is a Trademark  of
  478.  Microsoft  Corporation;  Microcom, Microcom Network Protocol and MNP are all
  479.  trademarks or servicemarks of Microcom Corporation.
  480.    
  481. The contents of this newsletter are copyright (c) 1991 and may be copied whole
  482. or in part only if  original  credit is included. The GEnie UNIX RoundTable is
  483. not affiliated with AT&T.
  484. ay be copied whole
  485. or in part only if  origina